#include <iostream>
#include <string>

using namespace std;

// 2024. 考试的最大困扰度
// https://leetcode.cn/problems/maximize-the-confusion-of-an-exam/description/

class Solution {
public:
    int maxConsecutiveAnswers(string answerKey, int k) {
        int leftT = 0;
        int cntT = 0;
        int leftF = 0;
        int cntF = 0;
        int ans = 0;
        int n = answerKey.size();
        for (int i = 0; i < n; i++){
            char curCh = answerKey[i];
            curCh == 'T' ? cntT++ : cntF++;
            while(cntT > k){
                if(answerKey[leftF] == 'T'){
                    cntT--;
                }
                leftF++;
            }
            while(cntF > k){
                if(answerKey[leftT] == 'F'){
                    cntF--;
                }
                leftT++;
            }
            ans = max(ans, max(i - leftT + 1, i - leftF + 1));
        }
        return ans;
    }
};

int main()
{
    return 0;
}